home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / CMPLTPAS / VARDUMP.PAS < prev    next >
Pascal/Delphi Source File  |  1988-07-24  |  2KB  |  53 lines

  1. {->>>>VarDump<<<<----------------------------------------------}
  2. {                                                              }
  3. { Filename : VARDUMP.SRC -- Last Modified 7/14/88              }
  4. {                                                              }
  5. { This routine will display a hex dump of any variable or      }
  6. { typed constant passed in untyped VAR parameter Target.       }
  7. { VarDump calls WriteHex; be sure WriteHex is available.       }
  8. {                                                              }
  9. {     From: COMPLETE TURBO PASCAL 5.0  by Jeff Duntemann       }
  10. {    Scott, Foresman & Co., Inc. 1988   ISBN 0-673-38355-5     }
  11. {--------------------------------------------------------------}
  12.  
  13. PROCEDURE VarDump(VAR Device : Text; VAR Target; ItSize : Integer);
  14.  
  15. CONST
  16.   Printables : SET OF Char = [' '..'}'];
  17.  
  18. VAR
  19.   I,J       : Integer;
  20.   Full,Left : Integer;
  21.   DumpIt    : ARRAY[0..MAXINT] OF Byte ABSOLUTE Target;
  22.  
  23. PROCEDURE DumpLine(Offset,ByteCount : Integer);
  24.  
  25. VAR
  26.   I : Integer;
  27.  
  28. BEGIN
  29.   FOR I := 0 TO ByteCount-1 DO               { Hex dump the data }
  30.     BEGIN
  31.       WriteHex(Device,DumpIt[(Offset*16)+I]);
  32.       Write(Device,' ')
  33.     END;
  34.   FOR I := 0 TO 56 - (ByteCount*3) DO Write(Device,' ');  { Space interval }
  35.     Write(Device,'|');                       { Show first boundary bar }
  36.   FOR I := 0 TO ByteCount-1 DO               { Show printable equivalents }
  37.     IF Chr(DumpIt[(Offset*16)+I]) IN Printables THEN
  38.       Write(Device,Chr(DumpIt[(Offset*16)+I]))
  39.     ELSE Write(Device,'.');
  40.   Writeln(Device,'|')                        { Final boundary bar }
  41. END;
  42.  
  43.  
  44. BEGIN
  45.   Full := ItSize DIV 16;   { Number of 16-byte chunks in Target }
  46.   Left := ItSize MOD 16;   { 'Leftover' bytes after last 16-byte chunk }
  47.   FOR I := 0 TO Full-1 DO  { Not executed if less than 16 bytes in Target }
  48.     DumpLine(I,16);
  49.   IF Left > 0 THEN         { Not executed if size of Target divides by 16 }
  50.     DumpLine(Full,Left);
  51.   Writeln(Device)          { Space down one line after dump }
  52. END;  { VARDUMP }
  53.